package com.jinghang.wayofrich.activity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.*;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.Volley;
import com.jinghang.wayofrich.R;
import com.jinghang.wayofrich.adapter.BgImageViewAware;
import com.jinghang.wayofrich.adapter.IndexListAdapter;
import com.jinghang.wayofrich.beans.IndexArticle;
import com.jinghang.wayofrich.common.CustomRequest;
import com.jinghang.wayofrich.common.UrlConstant;
import com.nostra13.universalimageloader.core.ImageLoader;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 邀请会员,分享海报页面
 */
public class InviteVipShareActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_invite_vip_share);

        //头部文字和返回监听
        LinearLayout returnBack = findViewById(R.id.appbar_common_returback);
        returnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                InviteVipShareActivity.this.finish();
            }
        });
        TextView mTextView = findViewById(R.id.appbar_common_name);
        mTextView.setText("邀请会员");

        //从后台获取图片
        getInviteVipImg();
    }


    public void getInviteVipImg(){
        RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
        String url = UrlConstant.getReuqestUrl(UrlConstant.URL_GET_SHAREIMG);
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("type", "1");//渠道状态（0-禁用 1-启用）
        CustomRequest jsonObjectRequest = new CustomRequest(Request.Method.POST,
                url, hashMap, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("获取图片结果", jsonObject.toString());
                try{
//                    String imgUrl = jsonObject.getString("data");
                    String imgUrl = "http://pie4ovqb4.bkt.clouddn.com/1542551385524_invitevip.jpg";
                    ImageView imageView = findViewById(R.id.invite_vip_image);
                    ImageLoader.getInstance().displayImage(imgUrl, new BgImageViewAware(imageView));

                }catch (Exception e){

                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Log.d("请求出错", volleyError.getMessage());
            }
        });
        requestQueue.add(jsonObjectRequest);

    }
}
